import time

import yaml
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from page.basePage import basePage

with open(r'D:\PycharmProjects\ecShop\autoTest\driver\elements.yml', 'r' ,encoding='utf-8') as file:
    elements_config = yaml.safe_load(file)

class registerPage(basePage):
    url = 'http://localhost:8800/ecshop/'
    register_btn1 = By.XPATH,elements_config['register_page']['register_btn1']
    username_frm = By.XPATH,elements_config['register_page']['username_frm']
    email_frm = By.XPATH,elements_config['register_page']['email_frm']
    pwd_frm = By.XPATH,elements_config['register_page']['pwd_frm']
    enpwd_frm = By.XPATH,elements_config['register_page']['enpwd_frm']
    msn_frm = By.XPATH,elements_config['register_page']['msn_frm']
    qq_frm = By.XPATH,elements_config['register_page']['qq_frm']
    bgnum_frm = By.XPATH,elements_config['register_page']['bgnum_frm']
    jtnum_frm = By.XPATH,elements_config['register_page']['jtnum_frm']
    phonenum_frm = By.XPATH,elements_config['register_page']['phonenum_frm']
    pwdwt_select = By.XPATH,elements_config['register_page']['pwdwt_select']
    pwddn_frm = By.XPATH,elements_config['register_page']['pwddn_frm']
    inregister_btn2 = By.XPATH,elements_config['register_page']['inregister_btn2']
    msg_context = By.XPATH,elements_config['register_page']['msg_context']
    msg_context2 = By.ID,elements_config['register_page']['msg_context2']       #切换frame

    def click_register(self):
        self.find_Element(self.register_btn1).click()

    def send_username(self,username):
        self.find_Element(self.username_frm).send_keys(username)

    def send_email(self,email):
        self.find_Element(self.email_frm).send_keys(email)

    def send_pwd(self,password):
        self.find_Element(self.pwd_frm).send_keys(password)

    def send_enpwd(self,enpassword):
        self.find_Element(self.enpwd_frm).send_keys(enpassword)

    def send_msn(self,msn):
        self.find_Element(self.msn_frm).send_keys(msn)

    def send_qq(self,qq):
        self.find_Element(self.qq_frm).send_keys(qq)

    def send_bgnum(self,bgnum):
        self.find_Element(self.bgnum_frm).send_keys(bgnum)

    def send_jtnum(self,jtnum):
        self.find_Element(self.jtnum_frm).send_keys(jtnum)

    def send_phonenum(self,phonenum):
        self.find_Element(self.phonenum_frm).send_keys(phonenum)

    def select_pwdwt(self):
        ele = self.find_Element(self.pwdwt_select)
        select_ele = Select(ele)
        select_ele.select_by_index(1)

    def send_pwddn(self,pwddn):
        self.find_Element(self.pwddn_frm).send_keys(pwddn)

    def click_inregister(self):
        self.find_Element(self.inregister_btn2).click()

    def vip_register(self,username,email,password,enpassword,msn,qq,bgnum,jtnum,phonnum,pwddn):
        time.sleep(2)
        self.open(self.url)
        self.click_register()
        self.send_username(username)
        self.send_email(email)
        self.send_pwd(password)
        self.send_enpwd(enpassword)
        self.send_msn(msn)
        self.send_qq(qq)
        self.send_bgnum(bgnum)
        self.send_jtnum(jtnum)
        self.send_phonenum(phonnum)
        self.select_pwdwt()
        self.send_pwddn(pwddn)
        self.click_inregister()
        time.sleep(10)














